package com.yunzheng.studyLeaveSystem.modules.admin.show.condition.dao.lmpl;

import com.yunzheng.studyLeaveSystem.modules.admin.show.condition.dao.AdjustDao;
import com.yunzheng.studyLeaveSystem.modules.admin.show.condition.entity.adjuster;
import com.yunzheng.studyLeaveSystem.utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;


/**
 * Created with IntelliJ IDEA.
 *
 * @Author: YunZheng
 * @Date: 2023/01/30/10:52
 * @Description:获取时间为当天的数据库中的数据
 */

public class AdjustDaoImpl implements AdjustDao {
    @Override
    public List<adjuster> queryDay() throws Exception {
        Connection connection = DBUtils.getCon();
        List<adjuster> usersList = new ArrayList<>();

        String sql = "select name,term, direction,leave_class,adjust_date,adjust_class,reason from adjust where leave_date = curdate();";

        PreparedStatement preparedStatement = connection.prepareStatement(sql);

        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            adjuster adjuster = new adjuster();
            adjuster.setName(resultSet.getString("name"));
            adjuster.setTerm(resultSet.getString("term"));
            adjuster.setDirection(resultSet.getString("direction"));
            adjuster.setLeave_class(resultSet.getString("leave_class"));
            adjuster.setAdjust_date(resultSet.getString("adjust_date"));
            adjuster.setAdjust_class(resultSet.getString("adjust_class"));
            adjuster.setReason(resultSet.getString("reason"));
            usersList.add(adjuster);
        }
        DBUtils.release(resultSet, preparedStatement, connection);
        return usersList;
    }
}

